package com.github.niefy.modules.wx.entity;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.github.niefy.common.utils.Json;
import lombok.Data;
import me.chanjar.weixin.mp.bean.subscribe.WxMpSubscribeMessage;

import java.io.Serializable;
import java.util.Date;

/**
 * 订阅通知消息发送日志
 * @author liuxy
 * @date 2022-12-16
 */
@Data
@TableName("wx_sub_template_msg_log")
public class SubTemplateMsgLog implements Serializable {

    private static final long serialVersionUID = 1L;
    @TableId(type = IdType.AUTO)
    private Long logId;
    private String appid;
    private String touser;
    private String thirdId;
    private String templateId;
    private JSONObject data;
    private String contentColor;
    private String page;
    private JSONObject miniprogram;
    private Date sendTime;
    private String sendResult;

    public SubTemplateMsgLog() {
    }

    public SubTemplateMsgLog(WxMpSubscribeMessage msg, String thirdId, String appid, String sendResult) {
        this.appid = appid;
        this.touser = msg.getToUser();
        this.thirdId = thirdId;
        this.templateId = msg.getTemplateId();
        this.page = msg.getPage();
        this.miniprogram = JSONObject.parseObject(JSON.toJSONString(msg.getMiniProgram()));
        this.data = JSONObject.parseObject(JSON.toJSONString(msg.getDataMap()));
        this.contentColor = msg.getContentColor();
        this.sendTime = new Date();
        this.sendResult = sendResult;
    }

    @Override
    public String toString() {
        return Json.toJsonString(this);
    }

}
